From 8a0663cc7ff01905a18a7d693470b89fe865fdd1 Mon Sep 17 00:00:00 2001 From: robertlipe Date: Wed, 10 Jul 2013 03:29:40 +0000 Subject: [PATCH] Make GPX reader 9% faster just with a better hash. git-svn-id: http://gpsbabel.googlecode.com/svn/trunk@4417 f51c46e8-681c-474f-0cfe-069cfd0219fb --- gpsbabel/gpx.cc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/gpsbabel/gpx.cc b/gpsbabel/gpx.cc index da7b551b3..0c7eb5c10 100644 --- a/gpsbabel/gpx.cc +++ b/gpsbabel/gpx.cc @@ -443,17 +443,16 @@ tag_mapping tag_path_map[] = { {(tag_type)0, 0, NULL, 0UL} }; +// Maintain a fast mapping from full tag names to the struct above. +QHash hash; + static tag_type get_tag(const QString& t, int* passthrough) { - tag_mapping* tm; - unsigned long tcrc = get_crc32_s(t.toUtf8().data()); - - for (tm = tag_path_map; tm->tag_type_ != 0; tm++) { - if ((tcrc == tm->crc) && (t == tm->tag_name)) { - *passthrough = tm->tag_passthrough; - return tm->tag_type_; - } + tag_mapping* tm = hash[t]; + if (tm) { + *passthrough = tm->tag_passthrough; + return tm->tag_type_; } *passthrough = 1; return tt_unknown; @@ -464,7 +463,7 @@ prescan_tags(void) { tag_mapping* tm; for (tm = tag_path_map; tm->tag_type_ != 0; tm++) { - tm->crc = get_crc32_s(tm->tag_name); + hash[tm->tag_name] = tm; } } -- 2.30.2